package com.cs.cssupplier.controller;

import com.cs.cssupplier.domain.CsEnterprise;
import com.cs.cssupplier.domain.CsFinancialStatus;
import com.cs.cssupplier.mapper.CsWinningResultsMapper;
import com.cs.cssupplier.service.CsEnterpriseService;
import com.cs.cssupplier.service.CsFinancialStatusService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author：lyj
 * @Package：com.cs.cssupplier.controller
 * @Project：RuoYi-Cloud-master
 * @name：CsFinancialStatusController
 * @Date：2024/11/14 17:13
 * @Filename：CsFinancialStatusController
 */
@RestController
@RequestMapping("/financialStatus")
public class CsFinancialStatusController extends BaseController {
    @Resource
    private CsFinancialStatusService csFinancialStatusService;
    @Autowired
    private CsWinningResultsMapper mapper;
    /**
     * 根据id查询财务状态信息
     * @param c_id
     * @return
     */
    @GetMapping(value = "cd/{c_id}")
    public AjaxResult EnterpriseId(@PathVariable("c_id")Long c_id){
        System.out.println(AjaxResult.success(csFinancialStatusService.selectFinancialStatuscId(c_id)));
        return AjaxResult.success(csFinancialStatusService.selectFinancialStatuscId(c_id));
    }

    /**
     * 查询所有财务状态信息
     * @param csFinancialStatus
     * @return
     */
    @GetMapping("/list")
    public TableDataInfo list(CsFinancialStatus csFinancialStatus){
        startPage();
        List<CsFinancialStatus> list=csFinancialStatusService.selectFinancialStatusList(csFinancialStatus);
        return getDataTable(list);
    }

    /**
     * 添加财务状态信息
     * @param csFinancialStatus
     * @return
     */
    @PostMapping
    public AjaxResult insertFinancialStatus(@RequestBody CsFinancialStatus csFinancialStatus){
        return toAjax(csFinancialStatusService.addFinancialStatus(csFinancialStatus));
    }

    /**
     * 修改财务状态信息
     * @param csFinancialStatus
     * @return
     */
    @PutMapping
    public AjaxResult updateEnterprise(@RequestBody CsFinancialStatus csFinancialStatus){
        Long userid = SecurityUtils.getLoginUser().getUserid();
        Long sipplierByUserId = mapper.getSipplierByUserId(userid);//这才是供应商id
        csFinancialStatus.setHid(sipplierByUserId);
        System.out.println(csFinancialStatusService.updateFinancialStatus(csFinancialStatus));
        return toAjax(csFinancialStatusService.updateFinancialStatus(csFinancialStatus));
    }

    /**
     * 批量删除财务状态信息
     * @param c_id
     * @return
     */
    @DeleteMapping("/{c_id}")
    public AjaxResult deleteEnterprise(@PathVariable Long [] c_id){
        return toAjax(csFinancialStatusService.deleteListFinancialStatus(c_id));
    }
}
